﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace EasyFlow
{
    /// <summary>
    /// FlowInfoControl.xaml 的交互逻辑
    /// </summary>
    public partial class FlowInfoControl : UserControl
    {
        public FlowViewModel SelectedFlow
        {
            get { return (FlowViewModel)GetValue(SelectedFlowProperty); }
            set { SetValue(SelectedFlowProperty, value); }
        }
        public static readonly DependencyProperty SelectedFlowProperty =
            DependencyProperty.Register("SelectedFlow", typeof(FlowViewModel), typeof(FlowInfoControl), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));

        public ObservableCollection<FlowViewModel> FlowInfos
        {
            get { return (ObservableCollection<FlowViewModel>)GetValue(FlowInfosProperty); }
            set { SetValue(FlowInfosProperty, value); }
        }
        public static readonly DependencyProperty FlowInfosProperty =
            DependencyProperty.Register("FlowInfos", typeof(ObservableCollection<FlowViewModel>), typeof(FlowInfoControl), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
        public ICommand FlowSelectionChangedCommand
        {
            get { return (ICommand)GetValue(FlowSelectionChangedCommandProperty); }
            set { SetValue(FlowSelectionChangedCommandProperty, value); }
        }
        public static readonly DependencyProperty FlowSelectionChangedCommandProperty =
            DependencyProperty.Register("FlowSelectionChangedCommand", typeof(ICommand), typeof(FlowInfoControl), new PropertyMetadata(null));

        public FlowInfoControl()
        {
            InitializeComponent();
        }

        private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            FlowSelectionChangedCommand?.Execute(e.AddedItems[0] as FlowViewModel);
        }
    }
}
